<template>
  <div>
    <el-breadcrumb separator="/"><!--面包屑-->
      <el-breadcrumb-item :to="{ path: '/TestProductTemplateConfiguration' }"><i class="el-icon-s-home" style="margin-right: 15px;font-size: 16px"></i>试品模板</el-breadcrumb-item>
      <el-breadcrumb-item><i class="el-icon-menu" style="margin-right: 15px;font-size: 16px"></i>新增模板</el-breadcrumb-item>
    </el-breadcrumb>
    <div>
      <el-card v-loading="dataLoading[0]" :data="prodFrom" shadow="always" style="margin: 20px 20px 0;"><!--测试方案名称和描述-->
        <el-row><div class="rectangularBar"></div><span style="font-size: 20px;color:#6C59DD">基础信息</span></el-row>
        <el-form :model="prodFromName" :rules="prodFromNameRules" ref="prodFromName" label-width="100px" style="margin-top: 10px" size="small">
          <el-col :span="8">
            <el-form-item label="模板名称" prop="tpltName">
              <el-input v-model="prodFromName.tpltName" placeholder="请输入模板名称" size="small" style="width: 100%" clearable></el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="试品类型" prop="pkId">
              <el-select v-model="prodFromName.pkId" placeholder="请选择" filterable  @change="showProdType($event,'')" :disabled="this.typeDisabled" style="width: 100%" clearable>
                <el-option v-for="item in prodTypeList" :key="item.pk_id" :label="item.pk_ch_name" :value="item.pk_id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="试品名称" prop="prodId">
              <el-select v-model="prodFromName.prodId" placeholder="请选择" @change="showProdInfo($event)" :disabled="this.nameDisabled" style="width: 100%" clearable>
                <el-option v-for="item in prodNameList" :key="item.prod_id" :label="item.prod_name" :value="item.prod_id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
          <el-form :model="prodFrom" ref="prodFrom" label-width="100px" style="margin-top: 10px" size="small">
          <el-col :span="8">
            <el-form-item label="试品编号" prop="testProdNumber" >
              <el-input :disabled="true" v-model="prodFrom.prod_number" placeholder="请选择试品编号" size="small" style="width: 100%" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="相数" prop="phaseNumber" >
              <el-input :disabled="true" v-model="prodFrom.phases" placeholder="请选择相数" size="small" style="width: 100%" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="活门" prop="valve" >
              <el-input :disabled="true" v-model="prodFrom.valve" placeholder="请选择活门" size="small" style="width: 100%" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="观察窗" prop="viewingWindow" >
              <el-input :disabled="true" v-model="prodFrom.has_window" placeholder="请选择观察窗" size="small" style="width: 100%" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="试品元件" prop="testProdBody" >
              <el-input :disabled="true" v-model="prodFrom.element" placeholder="请选择试品元件" size="small" style="width: 100%" clearable></el-input>
            </el-form-item>
          </el-col> -->
        </el-form>
      </el-card>
    </div>
    <div>
      <el-card shadow="always" style="margin: 10px 20px 0;"><!--测试方案名称和描述-->
        <el-row>
          <div class="rectangularBar"></div>
          <span style="font-size: 20px;color:#6C59DD">试品部位</span>
          <el-button type="text" class="global_add" style="float:right;" size="small" @click="addProdBody(2)">+&nbsp;添加标志位</el-button> 
          <el-button type="text" class="global_add" style="float:right;" size="small" @click="addProdBody(1)">+&nbsp;添加试品部位</el-button> 
        </el-row>
        <el-table   :span-method="arraySpanMethod"  v-loading="dataLoading[2]" :data="testProdBodyForm" border :row-class-name="tableRowClassNameTow" @row-dblclick="tableDbEditThree" style="margin-top: 10px">
          <el-table-column fixed prop="index2" label="序号" width="100" align="center"></el-table-column>
          <el-table-column prop="testProdBodyForm" label="试品部位信息" align="center">
            <template slot-scope="scope">
              <el-select  v-if="scope.row.tp_type==1" v-model="scope.row.part_id" filterable allow-create default-first-option placeholder="请选择试品部位" style="width: 100%"  size="mini" clearable>
                <el-option v-for="item in testProdBodyNameForm" :key="item.part_id" :label="item.part_name" :value="item.part_id"></el-option>
              </el-select>
              <el-row v-if="scope.row.tp_type==2">
                <el-input clearable v-if="scope.$index==triggerEditThree" @blur="tableDbEditThree" v-model="scope.row.part_id" placeholder="请输入标志位名称"  size="mini"></el-input>
                  <span v-else-if="scope.row.part_id==''" style="color:#CCC4CF">双击输入标志位名称</span>
                  <span v-else >{{scope.row.part_id}}</span> 
              </el-row>
            </template>
          </el-table-column>
          <el-table-column prop="testProdBodyForm" label="大气校正标准" align="center">
            <template slot-scope="scope">
              <el-select v-model="scope.row.cal_gjb" placeholder="请选择" autocomplete="center" @change="changecCalgjb(scope.row)"  style="width: 100%"  size="mini" clearable>
                <el-option v-for="item in calGjbList" :key="item.key" :label="item.label" :value="item.key"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="flag_bit" label="标志位" align="center">
                <template slot-scope="scope">
                  <el-input clearable v-if="scope.$index==triggerEditThree" @blur="tableDbEditThree" v-model="scope.row.flag_bit" placeholder="请输入标志位名称" size="mini"></el-input>
                  <span v-else-if="scope.row.flag_bit==''" style="color:#CCC4CF">双击输入标志位名称</span>
                  <span v-else >{{scope.row.flag_bit}}</span> 
                </template> 
              </el-table-column> -->
           <el-table-column prop="dis_electric" label="最小放电路径" align="center">
                <template slot-scope="scope">
                  <el-input clearable v-if="scope.$index==triggerEditThree" @blur="tableDbEditThree" v-model="scope.row.dis_electric" placeholder="请输入最小放电路径"  size="mini"></el-input>
                  <span v-else-if="scope.row.dis_electric==''" style="color:#CCC4CF">双击输入最小放电路径</span>
                  <!-- <span v-else-if="scope.row.dis_electric==''&&scope.row.cal_gjb!=16927.1" >1</span>  -->
                  <span v-else >{{scope.row.dis_electric}}</span> 
                </template> 
              </el-table-column>
              
          <el-table-column prop="remark" label="备注" align="center">
                <template slot-scope="scope">
                  <el-input clearable v-if="scope.$index==triggerEditThree" @blur="tableDbEditThree" v-model="scope.row.remark" placeholder="请输入备注，如分闸及对地"  size="mini"></el-input>
                  <span v-else-if="scope.row.remark==''" style="color:#CCC4CF">双击输入备注</span>
                  <span v-else >{{scope.row.remark}}</span> 
                </template> 
              </el-table-column>
          <el-table-column prop="config_status" label="配置状态" width="150" align="center">
             <template slot-scope="scope">
                <span v-if="scope.row.config_status==1" class="global_edit">已配置</span>
                <span v-else class="global_reset">待配置</span> 
              </template> 
          </el-table-column>
          <el-table-column label="操作" width="200"  align="center">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.tp_type==1"  @click="dialogTableVisible(scope.$index,scope.row)" size="small" style="color:#6C59DD">配置</el-button>
              <el-button type="text" size="small" style="color:#E83131" @click="deleteTestProdBody(scope.$index,scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <el-row style="margin-top: 20px;margin-bottom:20px;text-align:center">
        <el-button plain size="small" style="width:140px" class="textBtn" @click="cancel()">取消</el-button>
        <el-button type="primary" size="small" @click="saveValidate('prodFromName')" style="width:140px;margin-left:40px;background-color: #6C59DD;border-color: #6C59DD;">保存</el-button>
      </el-row>
      <el-dialog title="配置试品状态" :append-to-body="true" :visible.sync="state1">
          <el-button type="text" class="global_add" style="float:right;" size="small" @click="addProdBodyStatus()">+&nbsp;添加状态</el-button>
            <el-table id="editStatus" :data="rowBody"  @row-dblclick="tableDbEditTow" :row-class-name="tableRowClassName" highlight-current-row>
              <el-table-column prop="press_ground" label="加压接地部位" >
                <template slot-scope="scope">
                  <el-input v-if="scope.$index==triggerEditTow" @blur="tableDbEditTow" v-model="scope.row.press_ground" placeholder="请输入加压接地部位" size="mini" clearable></el-input>
                  <span v-else-if="scope.row.press_ground==''" style="color:#CCC4CF">双击输入加压接地部位</span>
                  <span v-else >{{scope.row.press_ground}}</span> 
                </template> 
              </el-table-column>
              <el-table-column prop="press_en_name" label="英文名称" >
                <template slot-scope="scope">
                  <el-input v-if="scope.$index==triggerEditTow" @blur="tableDbEditTow" v-model="scope.row.press_en_name" placeholder="请输入加压接地部位英文" size="mini" clearable></el-input>
                  <span v-else-if="scope.row.press_en_name==''" style="color:#CCC4CF">双击输入部位英文</span>
                  <span v-else >{{scope.row.press_en_name}}</span> 
                </template> 
              </el-table-column>
              <!-- <el-table-column prop="opc_status" label="合/分闸" show-overflow-tooltip align="center">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.opc_status" placeholder="请选择" autocomplete="center" style="width: 100%" size="mini">
                    <el-option v-for="item in opcStatusList" :key="item.key" :label="item.label" :value="item.key"></el-option>
                  </el-select>
                </template>
              </el-table-column> -->
               <!-- <el-table-column prop="positive_sign" label="正/负极" show-overflow-tooltip align="center">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.positive_sign" placeholder="请选择" autocomplete="center" style="width: 100%" size="mini">
                    <el-option v-for="item in positiveList" :key="item.key" :label="item.label" :value="item.key"></el-option>
                  </el-select>
                </template>
              </el-table-column> -->
              <el-table-column label="对应动作">
                <template slot-scope="scope">
                  <el-button v-if="scope.row.act_instruct.length==0" type="text" style="color:#5344AA" @click="selectAction(scope.$index,scope.row)">选择动作</el-button>
                  <el-button v-else size="60px" type="text" style="color:#5344AA" @click="selectAction(scope.$index,scope.row)">{{scope.row.act_instruct}}</el-button>
                </template>
              </el-table-column>
              <el-table-column label="操作" width="100">
                <template slot-scope="scope">
                  <el-button size="small" type="text" style="color:#E83131" @click="deleteTestProdBodyStatus(scope.$index,scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-drawer
              title="请选择动作"
              :visible.sync="state2" append-to-body size="25%">
            <!-- <el-dialog title="选择动作" :append-to-body="true" :visible.sync="state2" width=30%> -->
              <el-checkbox-group v-model="type">
                <el-row style="margin-left:20px">
                  <el-col :span="6" v-for="type in typeList" :key="type" >
                    <el-checkbox :label="type"  @change="handleCheckAllChange(type)">{{type}}</el-checkbox>
                  </el-col>

                </el-row>
                <div style="text-align:center;margin-top:300px">
                  <el-button size="small" class="textBtn" @click="selectActionFalse()">取 消</el-button>
                  <el-button  type="primary" style="background-color: #6C59DD;border-color: #6C59DD;" size="small" @click="selectActionTrue()">确 定</el-button>
                </div>
          </el-checkbox-group>
    <!-- </el-dialog>  -->
    </el-drawer>
            <div style="text-align:right;margin-top:20px">
              <el-button size="small" class="textBtn" @click="dialogTableVisibleFalse()">取 消</el-button>
              <el-button type="primary" style="background-color: #6C59DD;border-color: #6C59DD;" size="small" @click="dialogTableVisibleTrue()">确 定</el-button>
            </div>
          </el-dialog>
    </div>
  </div>
</template>
<script>
const uuid = require('node-uuid');
import Sortable from "sortablejs";
export default {
  components: {
    Sortable,
  },
  data() {
    return {
      // List: ['合kLi', '分kLi'],
      // List: [{id:1,test:'合kLi'},{id:1,test:'合kLi'}],
      // checkList: ['合kLi'],
      test:false,
      test1:false,
      dataLoading: [false,false,false,false],////数据加载前显示等待 0.试品基本信息，1.试品采集信息，2.试品部位信息，3.试品状态信息
      tpltId:'',
      prodId:'',
      pkId:'',
      tpltName: '',//试品模板名称
      checkAll: false,
      checkedCities: [],
      positiveList:[{key:0,label:'负极'},{key:1,label:'正极'},{key:2,label:'正负极'}],
      opcStatusList:[{key:1,label:'合闸'},{key:0,label:'分闸'}],
      type :[],//动作选择框
      typeList:["合kLi","分kLi","合kh5","分kh5",
                "合km","分km","合kh6","分kh6",
                "合kac","分kac", "合ke1","分ke1",
                "合kef","分kef","合ke2","分ke2",
                "合kh1","分kh1","合ke3","分ke3",
                "合kh2","分kh2","合ke4","分ke4",
                "合kh3","分kh3","合ke5","分ke5",
                "合kh4","分kh4","合ke6","分ke6"
              ],
      isIndeterminate: true,
      state1: false,
      state2: false,
      formLabelWidth: '120px',
      triggerEditOne:-1,
      triggerEditTow:-1,
      triggerEditThree:-1,
      typeDisabled: false,//类型下拉框禁用
      nameDisabled: true,//名称下拉框禁用
      testProdName:'',//试品类型
      indexStatus:'',//记录状态行下标
      rowStatus:'',//记录状态行数据
      indexBody:'',//记录试品部位下标
      rowBody:[],//记录试品部位行数据
      calGjbList: [
        {
            key: '不允许',
            label: '不允许'
          },
          {
            key: '16927.1',
            label: '16927.1'
          },
          {
            key: '11022',
            label: '11022'
          }
      ],
      oldStatus:'',
      deleteForm:[],
      testProdBodyNameForm : [],//试品部位名称下拉框
      con : 0,
      allprodFrom : [],//存放所有基本信息
      prodTypeList : [],
      prodNameList : [],
      prodFrom : {},//基本信息表
      prodNameSelect: [],
      prodFromName:{//存放模板名称与试品类型与名称表单
        tpltName: '',//试品模板名称
        tpltId:'',
        prodId:'',
        pkId:'',
      },
      tableData: [],//试品信息表
      testProdBodyForm: [],//试品部位表
      prodFromNameRules: {
        tpltName: [
          { required: true, message: '请输入模板名称', trigger: 'blur' },
          { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' },
          {
            required: true,
            pattern: /^[\u4e00-\u9fa5a-zA-Z-z0-9]+$/,
            message: '模板名称不支持特殊字符',
            trigger: 'blur'
          }
        ],
        prodId: [
          { required: true, message: '请选择试品名称', trigger: 'change' },
        ]
      },  
    }
  },
  mounted () {
    this.init();
  },
  methods:{
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
        if (row.tp_type === 2) { 
          if (columnIndex === 0) {
            return [1,1];
          }
          else if (columnIndex === 1) {
            return [1,5];
          } 
          else if (columnIndex === 2) {
            return [0,0];
          }
          else if (columnIndex === 3) {
            return [0,0];
          }
          else if (columnIndex === 4) {
            return [0,0];
          }
          else if (columnIndex === 5) {
            return [0,0]}
           
          
        }
      },

    handleCheckAllChange(value) {
      let prefixCode=value.slice(0,1);
      let suffixCode=value.slice(1);
      let judgeCode='';
      if(prefixCode=='分'){
        judgeCode='合'+suffixCode;
      }
      else{
        judgeCode='分'+suffixCode;
      }
      this.type.forEach((item,index)=>{
        if(item==judgeCode){
          this.type.splice(index, 1); 
          return;
        }
      })
    },
    //获取下拉框信息
    async getProdNameData() {//获取试品名称下拉框选项及所有基本信息
      let ret = await this.$http.get("/testProdTemplate/getProductKind",);
      this.prodTypeList=ret.result;
      ret = await this.$http.get("/testProdTemplate/getProdBodyNameSelect",);
      this.testProdBodyNameForm = ret.result;
    },
    async init(){
      await this.getProdNameData();
      const params = this.$route.query;
      if(params.sign === 'edit'){
        this.prodFromName=params.prodFromName;
        // await this.showProdType(this.prodFromName.pkId,this.prodFromName.prodId);
        // await this.showProdInfo(this.prodFromName.prodId)
        let ret = await this.$http.get("/testProdTemplate/getProdBodySelect",{params:{tpltId:this.prodFromName.tpltId}});
        this.testProdBodyForm = ret.result;//试品部位信息存放数组
      }
      this.openPull();
    //  this.openStatusPull();
    },
    async openPull() {
      const tbody = document.querySelector("#editTable tbody"); //此处editTable只是html的标签Id
      const _this = this;
      
      console.info("44444477777777777")
      Sortable.create(tbody, {
        sort: true,
        onEnd: function (evt) {
          // 对原数组进行操作.
          _this.testProdBodyForm.splice(
            evt.newIndex,
            0,
            _this.testProdBodyForm.splice(evt.oldIndex, 1)[0]
          );
        },
      });
    },
    async openStatusPull() {
      const tbody = document.querySelector("#editStatus tbody"); //此处editTable只是html的标签Id
      console.info("44444444444444444")
      const _this = this;
      console.info(_this.rowBody);
      Sortable.create(tbody, {
        sort: true,
        onEnd: function (evt) {
          // 对原数组进行操作.
          _this.rowBody.splice(
            evt.newIndex,
            0,
            _this.rowBody.splice(evt.oldIndex, 1)[0]
          );
        },
      });
    },
    // async showProdType(event,prodId){//获取试品类型下拉框
    //   let ret = await this.$http.get("/testProdTemplate/getProductInfo",{params:{pkId:event}});
    //   this.prodNameList=ret.result;
    //   this.nameDisabled=false;
    //   this.prodFromName.prodId=prodId;
    //   this.prodFrom={};
    // },
    changecCalgjb(row){
      console.info(row);
      if(row.cal_gjb!='16927.1'){
        row.dis_electric= "1"
      }
      else{
        row.dis_electric= ""
      }
    },
    async showProdInfo(event){
      for( let i = 0; i < this.prodNameList.length; i++) {
        if(event == this.prodNameList[i].prod_id) {
          this.prodFrom= this.prodNameList[i];
        }
      }
    },
    //点击确定隐藏子弹窗
    async selectActionTrue(){
      console.info(this.type);
      let flag=0;
      let flag2=0;
      if(this.type.length==17){
        let status = '';
        for (let i = 0; i < this.type.length; i++){
          if(this.type[i] != ''){
            status = status + this.type[i] + ";";
          }
          if(this.type[i]=='合kLi'||this.type[i]=='合kac'){
            flag++;
          }
          if(this.type[i]=='合kac'||this.type[i]=='合km'){
            flag2++;
          }
        }
        if(flag==2||flag2==2){
          this.$message({
            showClose: true,
            message: "合kac动作与合kLi,合km不可同时选择",
            type: "warning",
          });
          return;
        }
        this.state2 = false;
        this.rowBody[this.indexStatus].act_instruct = status;
      }else{
        this.$message({
          showClose: true,
          message: "动作配置不全，请继续",
          type: "warning",
        });
      }
    },
    //点击取消隐藏子弹窗
    selectActionFalse(){
      this.state2 = false;
      // this.rowBody = this.testProdBodyForm[this.indexBody].bodyStata;
    },
    //显示子弹窗
    selectAction(index, row){
      this.state2 = true;
      this.indexStatus = index;
      this.rowStatus = row;
      this.type = (row.act_instruct).split(";");
      this.oldStatus = row.act_instruct;
    },
    //点击取消隐藏试品组合状态弹窗
    async dialogTableVisibleFalse(){
      this.state1 = false;
      this.rowBody = this.testProdBodyForm[this.indexBody].bodyStata;
      console.info("44444455544444444444")
    },
    //点击确定隐藏试品组合状态弹窗
    async dialogTableVisibleTrue(){
      if(this.rowBody.length!=0){
        var hash = {};
        let flag=0;
        for(let i=0;i<this.rowBody.length;i++){
          if(this.rowBody[i].act_instruct.length==0||this.rowBody[i].press_ground.length==0){
            console.info(this.rowBody[i]);
            this.$message({
              showClose: true,
              message: "配置信息不能为空，请检查!",
              type: "warning",
            });
            return;
          }
        
          if(hash[this.rowBody[i].press_ground]) {
            // this.rowBody.find((item, index) => {
            //   if(item.press_ground==this.rowBody[i].press_ground&&index!=i){
            //     if(this.rowBody[i].opc_status==item.opc_status){
            //       flag=1;
            //     }
            //   }
            // })
            flag=1;
          }
          if(flag==1){
            this.$message({
                    showClose: true,
                    message: "加压接地部位不可重复!",
                    type: "warning",
                  });
                  return;
          }
          hash[this.rowBody[i].press_ground] = true;  
        }
        this.state1 = false;
        this.testProdBodyForm[this.indexBody].bodyStata = this.rowBody;
        this.testProdBodyForm[this.indexBody].config_status = 1;//更新状态表
      }
      else{
        this.$message({
          showClose: true,
          message: "请输入配置信息!",
          type: "warning",
        });
      }
    },
    //点击配置显示试品组合状态弹窗
    async dialogTableVisible(index, row){
      this.state1 = true;
      this.indexBody = index;
      this.rowBody = JSON.parse(JSON.stringify(this.testProdBodyForm[index].bodyStata));
      this.partId = row.part_id;
      console.info("}}}}}}}}}}}}}}}}")
      this.openStatusPull();
    },
    //删除试品部位部分表格行
    deleteTestProdBody(index,row){
      this.testProdBodyForm.splice(index, 1);
      if(row.tp_id){
        this.deleteForm.push(row.tp_id);
      }
    },
    //删除试品部位状态部分表格行
    deleteTestProdBodyStatus(index,row){
      this.rowBody.splice(index, 1);
    },
   
    //照片采集部分索引
    tableRowClassName ({row, rowIndex}) {
      //把每一行的索引放进row
      row.index = rowIndex;
      row.index1 = rowIndex+1;
    },
    tableRowClassNameTow ({row, rowIndex}) {//索引
      //把每一行的索引放进row
      row.index = rowIndex;
      row.index2 = rowIndex+1;
    },
    tableDbEditOne(row){
        this.triggerEditOne=row.index;
    },
    tableDbEditTow(row){
        this.triggerEditTow=row.index;
    },
    tableDbEditThree(row){
        this.triggerEditThree=row.index;
    },
    //添加试品部位
    addProdBody(type){
      let addData = {
        part_id : '',
        remark:'',
        dis_electric:0,
        config_status : 0,
        cal_gjb : '',
        flag_bit:'',
        bodyStata : [],
        tp_type:type 
      };
      if(type==2){
        addData.bodyStata.push({
            press_ground: null,
            press_en_name:null,
            act_instruct: null,
            positive_sign:null,
            opc_status: null,
          });
      }
      this.testProdBodyForm.push(addData);
    },
    //添加试品状态
    addProdBodyStatus(){
      let addData = {
        act_instruct : '',
        // opc_status:1,
        // positive_sign:2,
        press_ground : '',
        press_en_name : '',
      };
      this.rowBody.push(addData);
    },
   
    //效验通过更新数据
    async updateData(){
      console.info(this.deleteForm);
      const template = {//模板基础信息
        prodFromName:this.prodFromName,
        testProdBodyForm:this.testProdBodyForm,
        deleteForm:this.deleteForm
      }
      let ret;
      if(this.prodFromName.tpltId.length==0){
        ret = await this.$http.post("/testProdTemplate/addTemplate",template);
      }
      else{
        ret = await this.$http.put("/testProdTemplate/updateTemplate",template);
      }
      if(ret.code==200){
        this.$router.push({
          path: '/TestProductTemplateConfiguration'
        });
      }
      else{
        this.$message({
          showClose: true,
          message: ret.message,
          type: ret.type,
        });
      } 
    },
    //保存数据
    saveValidate(prodFromName) {
      var hash = {};
      let falg = false;
      let flag2=0;
      this.$refs[prodFromName].validate((valid) => {
          if (!valid) {
            falg = true;
          }
      });
      if (falg) {
        return;
      }
      if (this.testProdBodyForm.length == 0) {
        this.$message({
          showClose: true,
          message: "试品部位不能为空!",
          type: "warning",
        });
        return;
      }
      let warnMessage='';
      console.info(this.testProdBodyForm);
      for(let i=0;i<this.testProdBodyForm.length;i++){
        if(this.testProdBodyForm[i].config_status==0&&this.testProdBodyForm[i].tp_type==1){
          warnMessage='状态配置不能为空！'
        } 
        if(this.testProdBodyForm[i].dis_electric.length==0&&this.testProdBodyForm[i].tp_type==1){
          warnMessage='最小放电路径不能为空！'
        } 
        if(this.testProdBodyForm[i].cal_gjb.length==0&&this.testProdBodyForm[i].tp_type==1){
          warnMessage='大气校正标准不能为空！'
        }
        if(this.testProdBodyForm[i].part_id.length==0){
          warnMessage='试品部位名称不能为空！'
        }
        // if(this.testProdBodyForm[i].flag_bit.length==0){
        //   warnMessage='标志位不能为空！'
        // }
        if(warnMessage.length!=0){ 
          this.$message({
            showClose: true,
            message: warnMessage,
            type: "warning",
          });
          return;
        }
        if(hash[this.testProdBodyForm[i].part_id]){
          this.testProdBodyForm.find((item, index) => {
              if(item.part_id==this.testProdBodyForm[i].part_id&&index!=i){
                if(this.testProdBodyForm[i].remark==item.remark){
                  flag2=1;
                }
              }
            })
        }
        if(flag2==1) {
            this.$message({
              showClose: true,
              message: "相同试品部位备注不可重复!",
              type: "warning",
            });
            return;
          }
        hash[this.testProdBodyForm[i].part_id] = true;    
      }
      console.info(this.testProdBodyForm);
      this.updateData();
    },
    //点击取消
    async cancel(){
      this.$router.push({
          path: '/TestProductTemplateConfiguration'
      });
    },
  },
  
}
</script>
<style lang="scss" scoped>
@import "./EditTestProdTemplate.scss";
</style>